package com.sunyard.domee.dubbo;

import com.alibaba.dubbo.config.annotation.Service;
import com.sunyard.domee.api.MarketingCouponQueryApi;
import com.sunyard.domee.commons.model.RPCResultModel;
import com.sunyard.domee.dal.query.MarketingCouponQuery;
import com.sunyard.domee.dubbo.convert.MarketingCouponConvert;
import com.sunyard.domee.handler.MarketingCouponHandler;
import com.sunyard.domee.response.MarketingCouponResponse;
import com.sunyard.domee.service.bo.MarketingCouponBO;

import javax.annotation.Resource;
import java.util.List;
import java.util.Set;

/**
 * @author jinrao
 * @program domee
 * @description
 * @create 2020-07-21 15:48
 */
@Service(version = "1.0.0", timeout = 3000)
public class MarketingCouponQueryApiImpl implements MarketingCouponQueryApi {
    @Resource
    private MarketingCouponHandler marketingCouponHandler;

    @Override
    public RPCResultModel<MarketingCouponResponse> findEffective(Long id) {
        MarketingCouponBO effective = marketingCouponHandler.findEffective(id);
        return new RPCResultModel<>(MarketingCouponConvert.toResponse(effective));
    }

    @Override
    public RPCResultModel<List<MarketingCouponResponse>> findEffectiveSet(Set<Long> ids) {
        List<MarketingCouponBO> list = marketingCouponHandler.findEffectiveSet(ids);
        return new RPCResultModel<>(MarketingCouponConvert.toResponseList(list));
    }

    @Override
    public RPCResultModel<List<MarketingCouponResponse>> findCouponByName(String couponName) {
        MarketingCouponQuery query = new MarketingCouponQuery();
        query.setCouponName(couponName);
        List<MarketingCouponBO> list = marketingCouponHandler.findListValid(query);
        return new RPCResultModel<>(MarketingCouponConvert.toResponseList(list));
    }
}
